package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.model.product.BaseSaleAttr;
import com.atguigu.gmall.model.product.SpuInfo;
import com.atguigu.gmall.product.service.ManageService;
import com.atguigu.gmall.product.service.SpuInfoService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "商品SPU管理")
@RestController
@RequestMapping("admin/product")
public class SpuManageController {

    @Autowired
    private SpuInfoService spuInfoService;

    @Autowired
    private ManageService manageService;


    @GetMapping("{page}/{size}")
    public Result getSpuInfoPage(@PathVariable("page") Long page,
                                 @PathVariable("size") Long size,
                                 SpuInfo spuInfo){

        Page<SpuInfo> spuInfoPage = new Page<>(page, size);

        IPage<SpuInfo> spuInfoIPageList = spuInfoService.getSpuInfoPage(spuInfoPage,spuInfo);

        return Result.ok(spuInfoIPageList);

    }

    @ApiOperation("查询基本销售属性列表")
    @GetMapping("baseSaleAttrList")
    public Result baseSaleAttrList(){

        List<BaseSaleAttr> baseSaleAttrList = manageService.getBaseSaleAttrList();
        return Result.ok(baseSaleAttrList);

    }

    @PostMapping("saveSpuInfo")
    public Result saveSpuInfo(@RequestBody SpuInfo spuInfo){
        spuInfoService.saveSpuInfo(spuInfo);
        return Result.ok();
    }



}
